package com.cslc.wechat.faultreport.service.impl;

import org.apache.log4j.Logger;

import com.cslc.wechat.common.bean.Clerk;
import com.cslc.wechat.common.bean.Pending;
import com.cslc.wechat.common.dao.HibernateDao;
import com.cslc.wechat.faultreport.service.IFaultReportService;

public class FaultReportServiceImpl implements IFaultReportService{
	private static Logger logger = Logger.getLogger(FaultReportServiceImpl.class);
	private HibernateDao hibernateDao;


	@Override
	public boolean isClerkBindTerminal(String openid) {
		//获取clerk对象
		String hql = "from Clerk c where c.openid = ?";
		String param = openid;
		Clerk clerk = (Clerk) hibernateDao.findUniqueObjByParam(hql, param);
		
		//clerk中不存在terminal，即未绑定任何终端
		if(null == clerk.getTerminals() || clerk.getTerminals().isEmpty())
			return false;
		else
			return true;
	}
	
	@Override
	public Clerk getClerkWithOpenid(String openid) {
		//获取clerk对象
		String hql = "from Clerk c where c.openid = ?";
		String param = openid;
		Clerk clerk = (Clerk) hibernateDao.findUniqueObjByParam(hql, param);
		return clerk;
	}

	

	@Override
	public void addPendingEvent(Pending pending) {
		hibernateDao.insert(pending);
	}

	


	public HibernateDao getHibernateDao() {
		return hibernateDao;
	}


	public void setHibernateDao(HibernateDao hibernateDao) {
		this.hibernateDao = hibernateDao;
	}

}
